<?php

function parse_input($sen){
	$sen = strtolower($sen);
	$sen = remove_punctuations($sen);
	$sen = trim(remove_unnecessary_words($sen));
	$result = str_replace(" ", ",", preg_replace('/ +/', ' ', $sen));

	return trim($result);
}

function remove_punctuations($sen){
	$sen = $sen . " ";
	$file = fopen('./text_files/punctuations.txt', 'r');
	while (!feof($file)) {
		$word = trim(fgets($file));
		if(strpos($sen, $word))
		{
			$line_of_text = $word;
			$sen = str_replace($line_of_text, " ", $sen);
		}
	};
	fclose($file);

	return $sen;
}

function remove_unnecessary_words($sen){
	$sen = $sen . " ";
	$file = fopen('./text_files/unnecessary_words.txt', 'r');
	while (!feof($file)) {
		$word = trim(fgets($file));
		if(strpos($sen, $word))
		{
			$line_of_text = $word;
			$sen = str_replace($line_of_text, " ", $sen);
		}
	};
	fclose($file);

	return $sen;
}

#echo parse_input("Hi. Hello there. What is factset? Does it do something?");

?>